﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;



namespace GPCSC.Webs
{
    public class ReadXml
    {
        public ReadXml()
        { }
        private string strXMLPath=PubConstant.GetSqlTextPath;

        private string CommTypeXmlPath = PubConstant.GetCommTypeXml;

        /// <summary>
        /// 通过相应的查询的名称查询数据
        /// </summary>
        /// <param name="strSearchName">查询名称</param>
        /// <param name="commandParameters">查询参数</param>
        /// <returns>查询结果</returns>
        public System.Data.DataSet SearchData(string strSearchName, SqlParameter[] commandParameters)
        {
            XMLParse xmlParse = new XMLParse();
            string strCommandType = "";
            return DbHelperSQL.Query(xmlParse.ParseXML(strSearchName, ref strCommandType, strXMLPath), commandParameters);
        }


        /// <summary>
        /// 通过相应的查询的名称查询数据
        /// </summary>
        /// <param name="cmds">查询SqlCommand</param>
        /// <param name="strSearchName">查询名称</param>
        /// <returns>查询结果</returns>
        public System.Data.DataSet SearchData(SqlCommand cmds, string strSearchName)
        {
            XMLParse xmlParse = new XMLParse();
            string strCommandType = "";
            return DbHelperSQL.QuerySqlCommand(cmds, xmlParse.ParseXML(strSearchName, ref strCommandType, strXMLPath));
        }


        /// <summary>
        /// 通过相应的查询的名称查询数据
        /// </summary>
        /// <param name="strSearchName">查询名称</param>
        /// <returns>查询结果</returns>
        public System.Data.DataSet SearchData(string strSearchName)
        {
            SqlParameter[] dpdParm = new SqlParameter[0];
            return SearchData(strSearchName, dpdParm);
        }

        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>

        /// <returns>查询结果</returns>
        public ArrayList SearchALDate(string strSearchName)
        {
            XMLParse xmlParse = new XMLParse();
            return xmlParse.CommonTypeXML(strSearchName, CommTypeXmlPath);
        }

        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>
        /// <param name="IstrParentID">编号</param>
        /// <returns>查询结果</returns>
        public string SearchALDate(string strSearchName, string IstrParentID, string TypeListkind)
        {
            XMLParse xmlParse = new XMLParse();
            ArrayList ArryDa = xmlParse.CommonTypeOIDXML(strSearchName, CommTypeXmlPath, IstrParentID);
            if (ArryDa.Count > 0)
            {
                TypeList SearchName = (TypeList)ArryDa[0];
                if (TypeListkind.ToLower() == "id")
                {
                    return SearchName.ID;
                }
                else return SearchName.Name;
            }
            else
            {
                return SearchALDate(strSearchName, "00", TypeListkind);
            }
        }
        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>
        /// <param name="IstrParentID">编号</param>
        /// <returns>查询结果</returns>
        public DataTable SearchDateTable(string strSearchName)
        {
            XMLParse xmlParse = new XMLParse();
            ArrayList ArryDa = xmlParse.CommonTypeOIDXML(strSearchName, CommTypeXmlPath, "");
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", Type.GetType("System.String"));
            dt.Columns.Add("VALUE", Type.GetType("System.String"));
            if (ArryDa.Count > 0)
            {
                for (int i = 0; i < ArryDa.Count; i++)
                {
                    TypeList SearchName = (TypeList)ArryDa[i];
                    dt.Rows.Add(new object[] { SearchName.ID, SearchName.Name });
                }
            }
            return dt;

        }

        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>
        /// <param name="IstrParentID">编号</param>
        /// <returns>查询结果</returns>
        public DataTable SearchDateTable(string strSearchName, string TypeListkind)
        {
            XMLParse xmlParse = new XMLParse();
            ArrayList ArryDa = xmlParse.CommonTypeXML(strSearchName, CommTypeXmlPath, TypeListkind);
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", Type.GetType("System.String"));
            dt.Columns.Add("VALUE", Type.GetType("System.String"));
            if (ArryDa.Count > 0)
            {
                for (int i = 0; i < ArryDa.Count; i++)
                {
                    TypeList SearchName = (TypeList)ArryDa[i];
                    dt.Rows.Add(new object[] { SearchName.ID, SearchName.Name });
                }
            }
            return dt;

        }
 

        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>

        /// <returns>查询结果</returns>
        public int NotDoSQL(SqlCommand cmds, string strSearchName)
        {
            XMLParse xmlParse = new XMLParse();
            return DbHelperSQL.ExecuteSql(cmds, xmlParse.ParseXML(strSearchName, strXMLPath));
        }

        /// <returns>返回sql语句</returns>
        public String SqlBack(string strSearchName)
        {
            XMLParse xmlParse = new XMLParse();
            return xmlParse.ParseXML(strSearchName, strXMLPath);
        }


        /// <summary>
        /// 通过XML获得CommonType.xml中的类型信息
        /// </summary>
        /// <param name="strSearchName">查询名称</param>

        /// <returns>查询结果</returns>
        public DataSet DsDoSQL(SqlCommand cmds, string sql)
        {
            XMLParse xmlParse = new XMLParse();
            return DbHelperSQL.QuerySqlCommand(cmds, sql);
        }
      
        
    }
}
